package com.googlecode.yoohoo.xmppcore.stream.features;

import java.util.List;

import com.googlecode.yoohoo.xmppcore.protocol.IFeature;
import com.googlecode.yoohoo.xmppcore.protocol.translation.IXmlWriter;
import com.googlecode.yoohoo.xmppcore.protocol.translation.XmlWriter;

public class Mechanisms implements IFeature {
	private List<String> mechanisms;

	public List<String> getMechanisms() {
		return mechanisms;
	}

	public void setMechanisms(List<String> mechanisms) {
		this.mechanisms = mechanisms;
	}

	@Override
	public String toXml() {
		IXmlWriter writer = new XmlWriter();
		writer.writeStartElement("mechanisms");
		writer.writeNamespace("urn:ietf:params:xml:ns:xmpp-sasl");
		
		if (mechanisms != null) {
			for (String mechanism : mechanisms) {
				writer.writeStartElement("mechanism");
				writer.writeCharacters(mechanism);
				writer.writeEndElement();
			}
		}
		
		writer.writeEndElement();
		
		return writer.toXml();
	}
}
